package com.googlecode.animator.core
{
	import com.googlecode.animator.data.Notifications;
	import com.googlecode.data.stage.StagePropertiesVO;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	/**
	 * Ties in the main app. to PureMVC. 
	 * @author USER
	 * 
	 */
	public class AnimatorMediator extends Mediator
	{
		
		/**
		 * Identifier. 
		 */
		public static const NAME:String = "AnimatorMediator";
		
		private var _defaultXML:XML;
		
		/**
		 * Constructor. 
		 * @param viewComponent
		 * 
		 */
		public function AnimatorMediator(viewComponent:Revised3DAnimator)
		{
			super(NAME, viewComponent);
			
			
		}
		
		/**
		 * Set up the main app. 
		 * 
		 */
		override public function onRegister():void
		{	
			// ensure the 3D scene exists
			sendNotification(Notifications.ADD_SCENE_MODEL);
		}
		
		/**
		 * Clean up. 
		 * 
		 */
		/* override public function onRemove():void
		{
			_defaultXML = null;
		} */
		
		/**
		 * Link in with PureMVC framework. 
		 * @return 
		 * 
		 */
		override public function listNotificationInterests():Array
		{
			var list:Array = super.listNotificationInterests();
			
			list.push(Notifications.SCENE_ADDED);
			list.push(Notifications.DEFAULT_CAMERAS_ADDED_MODEL);
			list.push(Notifications.DEFAULT_VIEWPORTS_ADDED);
			/* 
			list.push(Notifications.DEFAULT_CAMERAS_ADDED);
			list.push(Notifications.CAMERA_ADDED); */
			
			return list;
		}
		
		/**
		 * Handle notifications. 
		 * @param notification
		 * 
		 */
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
				case Notifications.SCENE_ADDED:
					
					/* var loader:URLLoader = new URLLoader();
					loader.addEventListener(Event.COMPLETE, onXMLLoaded);
				
					var url:URLRequest = new URLRequest(ProjectConstants.DEFAULT_PROJECT_PATH);
					loader.load(url); */ 
					
					//sendNotification(Notifications.VIEWPORT_SETUP_COMPLETE);
					

					break;
				
				case Notifications.DEFAULT_CAMERAS_ADDED_MODEL:
					
					sendNotification(Notifications.ADD_CAMERA_PROXIES_MODEL);
					
					facade.removeMediator(getMediatorName());
					
					break;
					
				case Notifications.DEFAULT_VIEWPORTS_ADDED:
					
					//sendNotification(Notifications.ADD_SCENE);
					sendNotification(Notifications.ADD_DEFAULT_CAMERAS_MODEL);
					
					/* var stageObj:StagePropertiesVO = new StagePropertiesVO();
					
					sendNotification(Notifications.SET_STAGE_SIZE_MODEL, stageObj);
					sendNotification(Notifications.SET_WORK_AREA_VISIBLE, stageObj); */
					
					break;
			}
		}
		
		/**
		 * Handle the loaded XML for the project.
		 * @param evt
		 * 
		 */
		/* protected function onXMLLoaded(evt:Event):void*/
		//{
			//_defaultXML = new XML((evt.target as URLLoader).data);
			
			/* PropertiesPanel;
			PropertiesPanelMediator;
			ViewportMediator;
			MainViewportMediator;
			ZoomControl;
			ZoomControlMediator;
			ViewSelector;
			ViewSelectorMediator; */
			
			//sendNotification(Notifications.ADD_DEFAULT_VIEWPORTS, _defaultXML);
			//sendNotification(Notifications.ADD_DEFAULT_CAMERAS, _defaultXML);
			//sendNotification(Notifications.VIEWPORT_SETUP_COMPLETE);
			//sendNotification(Notifications.ADD_CAMERA_PROXIES, _defaultXML);
			
			//facade.removeMediator(getMediatorName());
		//} 
	
	}
}